<!DOCTYPE html>
<html>
<head>
<?php include_once VIEWS.'inc/head.php'; ?>
</head>
<style type="text/css">
	.article-textarea-box{
		box-sizing: border-box;
		width: 800px;
		font-size: 16px;
		line-height: 28px;
		color: #666;
		padding: 5px 10px;
		float: left;
	}
	.edui-editor{
		width: 800px!important;
		height: 300px!important;
	}
</style>
<body>
    <?php require_once VIEWS.'inc/header.php';?>
    <div class="main">
    	<div class="w980">
    		<div class="main-tit f-cb">
				<?php if($is_power) {?>
    			<a href="<?php echo site_url('information')?>" class="data">企业资料</a>
				<?php }?>
    			<a href="javascript:;" class="art cur">发布长文章</a>
    		</div>
    		<div class="main-content">
    			<form>
	    			<div class="main-line bb f-cb">
	    				<div class="main-title">标题:</div>
	    				<input type="text" class="main-input" name="title" id="title" value="" placeholder="请输入标题" maxlength="70">
	    			</div>
	    			<div class="main-line bb f-cb">
	    				<div class="main-title">文章详情:</div>
	    				<!-- <textarea class="main-textarea" id="content" name="content"></textarea> -->
	    				<div class="article-textarea-box">
	    					<script id="container" name="content" type="text/plain"></script>
	    				</div>
	    				
	    			</div>
	    			<div class="main-line bb f-cb">
	    				<div class="main-title">是否允许赞赏:</div>
	    				<div class="main-choosebox fl">
	    					<a href="javascript:;" class="cur">允许</a>
	    					<a href="javascript:;">不允许</a>
	    				</div>
	    			</div>
	    			<div class="main-line f-cb">
						<input type="hidden" name="is_zan" id="is_zan" value="1" />
	    				<input type="button" id="btn_submit" value="发布" class="main-sub">
	    			</div>
    			</form>
    		</div>
    	</div>
    </div>

<?php
	echo static_file('web/js/main.js');
	echo static_file('js/require.js');
	echo static_file('js/require.config.js');
	echo static_file('web/editor/ueditor.config.js');
	echo static_file('web/editor/ueditor.all.js');
?>

<script>
$(function(){
	var ue = UE.getEditor('container');

	$('.main-choosebox a').on('click',function(){
		if($('#is_zan').val() != 0) {
			$('#is_zan').val(0);
		} else {
			$('#is_zan').val(1);
		}
		$(this).addClass('cur').siblings().removeClass('cur');
	});
	$('#btn_submit').click(function() {
		var title = $('#title').val();
		var content = ue.getContent();
        if(!title) {
            alert('请输入标题');
            return false;
        }
        if(!content) {
            alert('请输入内容');
            return false;
        }
		var is_zan = $('#is_zan').val();
		var url = '<?php echo site_url('/article/add/')?>';
		$.ajax({
			url:url,
			type:'post',
			dataType:'json',
			data:{title:title,content:content,is_zan:is_zan,_scfs: $.cookie('_scfc')}
		}).done(function(data){
			if(data.status == 1) {
				alert(data.msg);
				window.location.href='<?php echo site_url('/article')?>';
			} else {
				var i=0;
				$.each(data.msg,function(putid,putv){
					i++;
					if(i==1){ alert(putv); }
				});
			}
		})
	});
})
</script>
<script type="text/javascript">
	require(['adminer/js/ui'],function(ui,media){
		// ueditor处理
		//ui.editor_create('content');
	});
</script>
</body>
</html>